package com.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.dto.Result;

import net.sf.json.JSONObject;

public class DataValidateUtil {
	
	 private static final Logger logger = LoggerFactory.getLogger(MobileValidateUtil.class);
	/**
     * 校验所有String参数都不为空(有空参数即返回true)
     * 
     * @param strings
     * @return
     */
    public static boolean checkNotEmpty(String... strings) {
        for (String string : strings) {
            if (null == string || "".equals(string)) {
                return true;
            }
        }
        return false;
    }
    
    /**
     * 校验指定JSONObject对象中参数是否为空(有空字符串则为true，否则返回false)
     * @param joParam
     * @param strings
     * @return
     */
    public static boolean checkNotEmptyByJson(JSONObject joParam,String...strings){
    	for(String string : strings){
    		String param = joParam.optString(string);
    		if(null == param || "".equals(param)){
    			logger.info("【此参数输入为空："+ string + "】");
    			
    			return true;
    			
    			
    		}
    	}
    	return false;
    }
    
    /**
     * 检查JSONObject对象中参数不能为空(返回缺少的参数)
     * @param joParam
     * @param param
     * @return
     */
    public static Result ckeckParam(JSONObject joParam, String ...param){
        StringBuffer result = new StringBuffer("");
        for (String key : param){
            String value = joParam.optString(key);
            if (value ==null || "".equals(value)){
                result.append(key).append(",");
            }
        }
        if(!"".equals(result.toString())){
            Result body = new Result();
            body.setState("1001");
            body.setMsg("参数缺失");
            JSONObject json = new JSONObject();
            json.put("缺少参数为",result.toString().substring(0,result.toString().length()-1));
            body.setData(json);
            return body;
        }else{
            return null;
        }
    }
    
    
    
    /**
     * 校验所有String参数是否都为空(都为空时为true,否则为false)
     * 
     * @param strings
     * @return
     */
    public static boolean checkEmpty(String... strings) {
        for (String string : strings) {
            if (null != string && !"".equals(string)) {
                return false;
            }
        }
        return true;
    }
}
